package cn.zhibang.sannuo.web.controller;

import cn.zhibang.sannuo.commons.model.Accountnumber;
import cn.zhibang.sannuo.commons.model.BranchOffice;
import cn.zhibang.sannuo.commons.model.HeadOffice;
import cn.zhibang.sannuo.pharmacy.service.HeadOfficeService;
import cn.zhibang.sannuo.pharmacy.service.PBranchOfficeService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.swing.*;

/**
 * @author AdminController
 * @version 1.0.0
 * @ClassName PharmacyController.java
 * @Description TODO 药房门店管理
 * @createTime 2021年03月29日 18:41:00
 */
@Controller
@RequestMapping("/pharmacy")
public class PharmacyController {
    @Resource private HeadOfficeService headOfficeService;
    @Resource private PBranchOfficeService pBranchOfficeService;

    @GetMapping("/store_list1")//总店列表
    public String store_list1(){
        return "html/store_list1";
    }
    @GetMapping("/store_edit1")//总店编辑
    public String store_edit1(HeadOffice headOffice, Model model){
        model.addAttribute("headOffice", headOffice);
        return "html/store_edit1";
    }
    @GetMapping("/store_add1")//新增总店页面
    public String store_add1(Model model){
        String hnumder = headOfficeService.selMaxHnumber();
        int i = Integer.parseInt(hnumder);
        i++;
        String number = null;
        if (i<10){
            number = "0"+i;
        }else if (i<100 && i >10){
            number = i+"";
        }
        model.addAttribute("hnumber", number+"001");
        return "html/store_add1";
    }
    @GetMapping("/store_list2")//分店列表
    public String store_list2(){
        return "html/store_list2";
    }

    @GetMapping("/store_add")//新增分店页面
    public String store_add(Model model){
        Subject subject = SecurityUtils.getSubject();
        Accountnumber accountnumber = (Accountnumber)subject.getPrincipal();
        BranchOffice branchOffice = accountnumber.getBranchOffice();
        HeadOffice headOffice = branchOffice.getHeadOffice();
        String hnumder = headOffice.getHnumder();
        String substring = hnumder.substring(0, 2);
        String s = pBranchOfficeService.selMaxBnumber(headOffice.getHid());
        int i = Integer.parseInt(s);
        i++;
        String number = null;
        if (i<10){
            number = "00"+i;
        }else if (i<100 && i >10){
            number = "0"+i;
        }else if (i<1000 && i>100){
            number = ""+i;
        }
        model.addAttribute("bnumber", substring+number);
        return "html/store_add";
    }

    @GetMapping("/store_edit")//编辑分店页面
    public String store_edit(BranchOffice branchOffice, Model model){
        model.addAttribute("branchOffice", branchOffice);
        return "html/store_edit";
    }

}
